/************************************************************************

Copyright (C) 2013 Georges Nader (georgesnader90@gmail.com). All rights reserved.

This file is part of gpe (Graphical Plot Editor).

gpe is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.

gpe is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with gpe.  If not, see <http://www.gnu.org/licenses/>.

************************************************************************/

#ifndef PLOTEDITOR_H
#define PLOTEDITOR_H

#include <vector>

enum InterpMethod{
  NO_INTERPOLATION, LINEAR_INTERPOLATION
};

class PlotEditor{
public:
  PlotEditor(std::vector<float>* plot=0, float minValue=-1.f, float maxValue=1.f)
    : _plot(plot),
      _interpMethod(NO_INTERPOLATION),
      _minValue(minValue),
      _maxValue(maxValue)
  {
    resetControlPoints();
  }
  ~PlotEditor(){}

  inline void setPlot(std::vector<float>* plot=0)
  {
    _plot = plot;
    resetControlPoints();
  }

  inline void addControlPoint   (unsigned int cntrlPt)
  {
    if(_plot && cntrlPt<_plot->size())
      _controlPoints[cntrlPt] = true;
  }
  inline void removeControlPoint(unsigned int cntrlPt)
  {
    if(_plot && cntrlPt<_plot->size()-1 && cntrlPt>0)
      _controlPoints[cntrlPt] = false;
  }

  inline void changeInterpolationMethod(InterpMethod interpMethod){
    _interpMethod = interpMethod;
  }

private:
  void resetControlPoints();

private:
  std::vector<float>* _plot;
  std::vector<bool>   _controlPoints;

  InterpMethod _interpMethod;

  float _minValue;
  float _maxValue;
};

#endif // PLOTEDITOR_H
